import { _decorator, Component, Node, view, EventTarget } from 'cc';
import { Constants, Orientation } from '../game/Constants';
import super_html_playable from '../game/super_html_playable';
import { EventListener } from '../core/EventListener';
const { ccclass, property } = _decorator;

@ccclass('UIManager')
export class UIManager extends Component {
    public static Instance: UIManager = null;
    public orientation: Orientation = Orientation.Portrait;

    onLoad() {
        UIManager.Instance = this;
        this.updateOrientation();
        view.on("canvas-resize", this.updateOrientation, this); //监听游戏尺寸变化
    }

    /**``           
     * 仅监听并赋值横竖屏状态
     */
    private updateOrientation() {
        const screenSize = view.getVisibleSize();
        const newOrientation = screenSize.width > screenSize.height ? Orientation.Landscape : Orientation.Portrait;
        if (this.orientation !== newOrientation) {
            this.orientation = newOrientation;
            EventListener.emit(Constants.Event_OrientationChange);
        }
    }

    /** 打开UI */
    public openLink() {
        super_html_playable.game_end();
        super_html_playable.download();
    }
}


